package cn.com.bluemoon.daps.model.utils.factory.impl.partition;

import cn.com.bluemoon.daps.model.dto.DapDataModelTableDto;
import cn.com.bluemoon.daps.model.entity.DapDataModelTablePartition;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author karry
 * @Data 2021/9/7
 * @Time:9:27
 */
public class HivePartitionScript extends AbsPartitionScript {

    @Override
    public String createPartitionScript(List<DapDataModelTablePartition> partitions) {

        List<String> list = Lists.newArrayList();
        partitions.forEach(partition -> {
            String partitionType = partition.getPartitionFieldType() == 1 ? "String":"Integer";
            String partitionComment = StringUtils.isBlank(partition.getName()) ? "" : String.format("comment '%s'", partition.getName());
            String single = String.format("%s %s %s", partition.getPartitionFieldName(), partitionType, partitionComment);
            String script = String.format(" PARTITIONED BY (%s)", single);
            list.add(script);
        });
        return list.stream().collect(Collectors.joining(","));
    }

    @Override
    public String addPartitionScript() {
        return null;
    }

    @Override
    public String modifyPartitionScript() {
        return null;
    }

    @Override
    public String deletePartitionScript() {
        return null;
    }

}
